home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nejlepší hry
/
Nejlepsi hry.iso
/
hry
/
plane arcade
/
planearcade.exe
/
tank3.bmp
/
main.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2004-09-28
|
12KB
|
528 lines
#include "main.h"
//--------------------------
//Globals
//--------------------------
DXFONT DFont;
MODEL SkyBoxSide;
MODEL SkyBoxTop;
SOUND MenuMusic;
SOUND GameMusic;
float MenuMusicTime = -1.0f;
float GameMusicTime = -1.0f;
//--------------------------
//Funkcie
//--------------------------
void InitializeScene();
void DestroyScene();
void SetProjectionScene();
void SetProjectionSkyBox();
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
//begin
Engine.BeginScene();
//ovladanie
Input.RefreshKeyboard();
Input.RefreshMouse();
//obnov svetla
LightManager.RefreshLights();
////////
//Menu//
////////
if (Menu.EnabledMenu == true)
{
//hudba
if (GameMusicTime != -1.0f)
{
GameMusic.Stop();
GameMusicTime = -1.0f;
}
if (MenuMusicTime == -1.0f && MusicEnabled)
{
MenuMusicTime = 0.0f;
}
if (MenuMusicTime == 0.0f && MusicEnabled)
{
MenuMusic.Play(true);
}
MenuMusicTime += PowerTime(0.01f);
if (MenuMusicTime > 295.0f && MusicEnabled)
{
MenuMusicTime = 0.0f;
}
//skry kurzor
ShowCursor(false);
//obnovi menu
Menu.Refresh();
}
/////////////
//Briefring//
/////////////
float zFPS = FPS; //pre casovanie hudby
if (Menu.EnabledBriefring == true)
{
//zvysi FPS - zastavi hru
FPS = 160000.0f;
}
////////
//Svet//
////////
if (Menu.EnabledMenu == false)
{
//hudba
if (MenuMusicTime != -1.0f)
{
MenuMusic.Stop();
MenuMusicTime = -1.0f;
}
if (GameMusicTime == -1.0f && MusicEnabled)
{
GameMusicTime = 0.0f;
}
if (GameMusicTime == 0.0f && MusicEnabled)
{
GameMusic.Play(true);
}
GameMusicTime += (1000.0f/zFPS) * 0.01f;
if (GameMusicTime > 400.0f && MusicEnabled)
{
GameMusicTime = 0.0f;
}
//Pridavanie objektov
Level.ProccesLevel();
//spitfire
SpitFire.Refresh();
//nastavi projekcnu maticu pre skybox
SetProjectionSkyBox();
//skybox
SkyBoxSide.Pos = Camera.Pos;
SkyBoxSide.Pos.Y = 2800.0f;
SkyBoxSide.Render();
SkyBoxTop.Pos = Camera.Pos;
SkyBoxTop.Pos.Y = 2700.0f;
SkyBoxTop.Render();
//nastavi projektcnu maticiu pre scenu
SetProjectionScene();
//krajina
Level.Refresh();
//renderspitfire
SpitFire.Render();
//explozie
Explo.Render();
//vyrenderuj skore napisy
Score.Refresh();
//vyrenderuje gui
Menu.DrawGui();
//vyrenderuje mapu
Menu.DrawMap();
//oznamy
SpitFire.DrawScreens();
//skry kurzor
ShowCursor(false);
//debug font
if (SpitFire.ShowFPS)
{
char cBuf[80];
sprintf(cBuf,"FPS: %d",iFPS);
DFont.Print(20,20,GetColor(1.0f,1.0f,0.0f,0.0f),cBuf);
}
}
/////////////
//Briefring//
/////////////
if (Menu.EnabledBriefring == true)
{
//zobrazi briefring
Menu.RefreshBriefring();
}
//!!Tento problem vystava iba pri nastaveni grafickej karty
//!!na slaby vykon, alebo je to tiez dobre kedze na zaciatku
//!!sa nacitava briefing
//!!Hack, zoberie silu
float Power;
Power = PowerTime(0.001f);
//end
Engine.EndScene();
//!!Hack ak stagetime == 0.0f+power FPS zvysit!!
if (Level.StageTime == 0.0f+Power && Menu.EnabledMenu == false)
FPS = 120.0f;
}
//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: The window's message handler
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
PostQuitMessage( 0 );
return 0;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
// Register the window class
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
WinClassName, NULL };
RegisterClassEx( &wc );
//zaciatok logu
LogStart();
//info o programe
LogPrint(ProgramInfo);
///////////////////////
//PRECITAJ NASTAVENIA//
///////////////////////
ReadConfigData();
////////////////////////
//MENITELNE NASTAVENIA//
////////////////////////
//SetUp Resotution
if (Resolution == 0)
{
Engine.Width = 640;
Engine.Height = 480;
}
if (Resolution == 1)
{
Engine.Width = 800;
Engine.Height = 600;
}
if (Resolution == 2)
{
Engine.Width = 1024;
Engine.Height = 768;
}
//SetUp Engine
Engine.Windowed = false;
Engine.Format = D3DFMT_X8R8G8B8;
Engine.TextureFormat = D3DFMT_A8R8G8B8;
Engine.Min = 10.0f;
Engine.Max = (float)DrawDistance;
Engine.BackColor = GetColor(1.0f,1.0f,1.0f,1.0f);
//nastav frustrum culling camery
Camera.MaxDis = (float)DrawDistance;
//stencil tiene
if (Shadows == 0)
Engine.StencilShadows = false;
else if (Shadows == 1)
Engine.StencilShadows = true;
////////////////////////////
//nastav okno pre windowed//
////////////////////////////
if(Engine.Windowed == true)
{
hWnd = CreateWindow( WinClassName, WinClassTittle,
WS_OVERLAPPEDWINDOW,
100, 100,Engine.Width, Engine.Height,
GetDesktopWindow(), NULL, wc.hInstance, NULL );
}
//////////////////////////////
//nastav okno pre fullscreen//
//////////////////////////////
if(Engine.Windowed == false)
{
hWnd = CreateWindowEx( WS_EX_APPWINDOW, // Extended Style For The Window
WinClassName, // Class Name
WinClassTittle, // Window Title
WS_POPUP | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
Engine.Width, // Calculate Window Width
Engine.Height, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
wc.hInstance, // Instance
NULL); // Dont Pass Anything To WM_CREATE
}
hIns = hInst;
////////////////////////////////////
//Nastavenia ktore sa nedaju menit//
////////////////////////////////////
//Initialize engine
Engine.Initialize();
Engine.SetZBuffer(true);
Engine.SetFilter(0,D3DTEXF_LINEAR);
Engine.SetFilter(1,D3DTEXF_LINEAR);
Engine.SetCullMode(D3DCULL_NONE);
Engine.SetShadeMode(D3DSHADE_GOURAUD);
Engine.SetMipMapping(0,true);
Engine.SetMipMapping(1,true);
Engine.MipMapLevels = 0;
//directInput
Input.Initialize();
//zvuk
InitializeSound();
//zobrazi okno
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );
//vstup do Message slucky
MSG msg;
ZeroMemory( &msg, sizeof(msg) );
//inicializacia svetiel pre lightmanager
LightManager.Initialize(1);
//debug font
DFont.Create(15,FW_BOLD,"Arial");
//editor
Editor.Initialize();
///////////////////////
//Inicializacia Sceny//
///////////////////////
InitializeScene();
////////////////
//message loop//
////////////////
while( msg.message!=WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
Render();
//Editor.RefreshEditor();
}
}
/////////////////
//Destroy sceny//
/////////////////
//znic level
Level.Destroy();
//vymaze svetla
LightManager.CleanUp();
//ukonci direct Input
Input.CleanUp();
//ukonci zvuk
CleanUpSound();
//Ukonci Engine
Engine.CleanUp();
//znici okno
UnregisterClass( WinClassName, wc.hInstance );
return 0;
}
//-----------------------------------------------------------------------------
// Name: InitializeScene()
// Desc: nastavy krajinu, svetla, ..
//-----------------------------------------------------------------------------
void InitializeScene()
{
//nastav menu
//---------------
Menu.Initialize();
//skore
//-----
Score.Initialize();
//Svetla
//------
LightManager.AddLightDir(Get3D(1.5f,-1.0f,1.5f),GetColor(1.6f,1.6f,1.6f,1.6f),
GetColor(0.3f,0.3f,0.3f,0.3f),
GetColor(1.0f,1.0f,1.0f,1.0f));
//Hmla
//----
g_pd3dDevice->SetRenderState(D3DRS_FOGCOLOR, 0xffffffff );
g_pd3dDevice->SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);
g_pd3dDevice->SetRenderState(D3DRS_FOGSTART, FtoDW((float)DrawDistance*0.50f));
g_pd3dDevice->SetRenderState(D3DRS_FOGEND, FtoDW((float)DrawDistance*0.75f));
//skyBox
//--------
Menu.DrawLoading(1,"Loading SkyBox");
SkyBoxSide.FrustrumTest = false;
SkyBoxSide.Lighting = false;
SkyBoxSide.InitializeAse(1,"scene/skyboxside.ase");
SkyBoxSide.LoadAse(0,"scene/skyboxside.ase");
SkyBoxSide.LoadTexture("scene/skySide.jpg",GetColor(0.0f,0.0f,0.0f));
SkyBoxSide.Sca = Get3D(250.0f,150.0f,250.0f);
SkyBoxTop.FrustrumTest = false;
SkyBoxTop.Lighting = false;
SkyBoxTop.InitializeAse(1,"scene/skyboxTop.ase");
SkyBoxTop.LoadAse(0,"scene/skyboxTop.ase");
SkyBoxTop.LoadTexture("scene/skyTop.jpg",GetColor(0.0f,0.0f,0.0f));
SkyBoxTop.Sca = Get3D(250.0f,150.0f,250.0f);
//stencil
//------------
Menu.DrawLoading(1,"Initalizing StencilShadow");
StencilShadow.Initialize();
//modely
//------
Menu.DrawLoading(2,"Loading Models");
ModelLib.Initialize();
//zvuky
//-----
Menu.DrawLoading(4,"Loading Sounds");
SoundLib.Initialize();
//SpitFire
//--------------
Menu.DrawLoading(5,"Loading SpitFire");
SpitFire.Initialize();
//svet
//-----
Menu.DrawLoading(6,"Initializing World");
Level.Initialize();
//Particles
//------------
Menu.DrawLoading(8,"Initializing Particle Systems");
Explo.Initialize();
//Hudba
//---------
if (MusicEnabled == 1)
{
MenuMusic.InitialiseForMP3();
MenuMusic.LoadSound("sounds/menumusic.mp3");
GameMusic.InitialiseForMP3();
GameMusic.LoadSound("sounds/gamemusic.mp3");
}
}
//-----------------------------------------------------------------------------
// Name: DestroyScene()
// Desc: znici krajinu
//-----------------------------------------------------------------------------
void DestroyScene()
{
//Svet
//----
Level.Destroy();
}
//-----------------------------------------------------------------------------
// Name: SetProjectionScene()
// Desc: nastavi projekcnu maticu pre renderovanie sceny
//-----------------------------------------------------------------------------
void SetProjectionScene()
{
D3DXMatrixPerspectiveFovLH( &matProj, 4.0f/3.0f,1.0f,Engine.Min, Engine.Max);
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}
//-----------------------------------------------------------------------------
// Name: SetProjectionSkyBox()
// Desc: nastavi projekcnu maticu pre renderovanie skyboxu
//-----------------------------------------------------------------------------
void SetProjectionSkyBox()
{
D3DXMatrixPerspectiveFovLH( &matProj, 4.0f/3.0f, 1.0f,Engine.Min, 25000);
g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}